package com.yongcheon.sms_manager.ui.phone_spam.actionTab;

import android.app.Fragment;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.yongcheon.sms_manager.R;
import com.yongcheon.sms_manager.data.contract.ContactData;
import com.yongcheon.sms_manager.data.phone_spsm.AbstractPhoneData;
import com.yongcheon.sms_manager.data.phone_spsm.PhoneData;
import com.yongcheon.sms_manager.data.phone_spsm.SpamPhonData;
import com.yongcheon.sms_manager.database.SpamDBManager;
import com.yongcheon.sms_manager.ui.phone_spam.list.PhoneCursorAdapter;
import com.yongcheon.sms_manager.ui.phone_spam.list.PhoneSPAMCurosrAdapter;

/**
 * Created by yongcheon on 2014-11-18.
 */
public class ActionTabPhoneFragment extends Fragment {
    AbstractPhoneData aData;
    ContactData contactData;

    public void setPhoneService(AbstractPhoneData aData){
        this.aData = aData;
    }
    public void setContactData(ContactData contactData){
        this.contactData = contactData;
    }

    public static ActionTabPhoneFragment newInstance(String texta) {
        ActionTabPhoneFragment frag = new ActionTabPhoneFragment();
        Bundle args = new Bundle();
        args.putString("TAB_NAME", texta);
        frag.setArguments(args);
        return frag;
    }


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        Bundle args = getArguments();
        String tabName = args.getString("TAB_NAME");

        View linear = inflater.inflate(R.layout.actiontabfragment, container, false);
        ListView smsList = (ListView)linear.findViewById(R.id.list);
        SQLiteDatabase database = SpamDBManager.getDatabase(container.getContext());
        if(aData instanceof PhoneData) {
            PhoneCursorAdapter adapter = (PhoneCursorAdapter) aData.getCurosrAdapter(container.getContext(), database);
            adapter.setPhoneService(aData);
            adapter.setContactData(contactData);
            smsList.setAdapter(adapter);
        }else if(aData instanceof SpamPhonData) {
            PhoneSPAMCurosrAdapter adapter = (PhoneSPAMCurosrAdapter) aData.getCurosrAdapter(container.getContext(), database);
            adapter.setPhoneService(aData);
            adapter.setContactData(contactData);
            smsList.setAdapter(adapter);
        }
        return linear;
    }

}
